# Maintainer: Andrea Zagli <andrea.zagli.free@gmail.com>

_realname=ghex
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=3.18.0
pkgrel=1
arch=('any')
pkgdesc="GNOME Hex editor for files (mingw-w64)"
options=(strip staticlibs)
depends=("${MINGW_PACKAGE_PREFIX}-gtk3"
         "${MINGW_PACKAGE_PREFIX}-adwaita-icon-theme")
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc"
             "${MINGW_PACKAGE_PREFIX}-pkg-config")
license=("GPL 2")
url="https://www.gnome.org"
install=ghex-${CARCH}.install
source=(https://download.gnome.org/sources/${_realname}/${pkgver%.*}/${_realname}-${pkgver}.tar.xz
        001-nohelp.patch
        002-fread.patch)
sha256sums=('c5b1eb50a8dd1334880b37617871498b778ea137f79bb43894ec68e4f63dc925'
            'cd87d0040cd37a942ff8a1e3013bc96083920dc959dac0a96b543b8b706585ff'
            '8e403c1e7c3f83adc768bfe45bb1ea42ae90fc4dfb7fe9bf4544820541a3241d')

prepare() {
  cd "${srcdir}"/${_realname}-${pkgver}

  patch -p0 -i ${srcdir}/001-nohelp.patch
  patch -p0 -i ${srcdir}/002-fread.patch

  autoreconf -ifv
}

build() {
  [[ -d build-${MINGW_CHOST} ]] && rm -rf build-${MINGW_CHOST}
  mkdir -p build-${MINGW_CHOST}
  cd build-${MINGW_CHOST}

  ../${_realname}-${pkgver}/configure \
    --host=${MINGW_CHOST} \
    --target=${MINGW_CHOST} \
    --build=${MINGW_CHOST} \
    --prefix=${MINGW_PREFIX} \
    --libexecdir=${MINGW_PREFIX}/lib

  make
}

package() {
  cd "${srcdir}/build-${MINGW_CHOST}"
  make DESTDIR=${pkgdir} install

  install -Dm644 "${srcdir}/${_realname}-${pkgver}/COPYING" "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/COPYING"
}
